home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1091 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: dgp.toronto.edu!victorng
  2. Newsgroups: comp.lang.c++
  3. From: victorng@dgp.toronto.edu (Victor Ng-Thow-Hing)
  4. Subject: Code loses this pointer value
  5. X-Nntp-Posting-Host: explorer.dgp.toronto.edu
  6. Message-ID: <1996Jan9.021817.24635@jarvis.cs.toronto.edu>
  7. X-Newsreader: NN version 6.5.0 #3 (NOV)
  8. Date: 9 Jan 96 07:18:17 GMT
  9.  
  10. Hi everyone, 
  11.  
  12. I have a particularly nasty bug in my C++ class code. Basically, the code
  13. loses track of the this pointer value that points to the object that is
  14. calling a member function. I have a class called bsplinevolume. The
  15. member function "build_Controlpoints" calls another member function
  16. "get_Skeleton_samp" as in the following short code snippet:
  17.  
  18. void bsplinevolume::build_Controlpoints()
  19. {
  20.      <stuff deleted>
  21.  
  22.      // Assign internal control points and interior cap ends.
  23.      double point[3];
  24.      for (int i=0; i<(N_s1-1); i++)
  25.          for (int j=0; j < N_s2; j++)
  26.              for (int k=0; k < N_s3; k++) {
  27.                   get_Skeleton_samp(i,j,k,point); // member function
  28.                   set_Controlpoint(i,j,k,point);  // member function
  29.              }
  30.  
  31.      <stuff deleted>
  32. }
  33.  
  34. When I run dbx on this code, if I type: print *this while in
  35. build_Controlpoints, I get the proper 'this' value:
  36.  
  37. (dbx) print *this
  38. class bsplinevolume {
  39.     N1 = 0x10004858
  40.     N2 = 0x10004908
  41.     N3 = 0x100049c8
  42.     Axis = 0x10004398
  43.     N_axis = 0
  44.     Cap1 = 0x100044c0
  45.     N_cap1 = 0
  46.     Cap2 = 0x10004730
  47.     N_cap2 = 0
  48.     Skeleton_samps = 0x10004a78
  49.     N_s1 = 10
  50.     N_s2 = 10
  51.     N_s3 = 10
  52.     Controlpoints = 0x1000a840
  53.     N_cpts = 1000
  54.  
  55. NOW, when I print *this while in get_Skeleton_samp, I get:
  56.  
  57. (dbx) print *this
  58. <no such address> 
  59.  
  60. and consequently all the variables in this method are full of garbage.
  61. You can see that 'this' has lost or corrupted its pointer value.      
  62.  
  63. I'm using the CC SGI c++ compiler on an Indigo2 Extreme.
  64.  
  65. Does anyone have any experience with this bug?
  66.  
  67. Regards,
  68. Victor.
  69.